package day_2022_4_to_7.day48;

import java.util.Scanner;

/**
 * @author haomin
 * @date 2022/04/22 22:56
 **/
public class Day5_2_ContinuousMaxSum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = 0;
        n = sc.nextInt();
        int[] num = new int[n];
        for (int i = 0; i < n; i++) {
            num[i] = sc.nextInt();
        }
        int max = num[0];
        int sum = num[0];
        for (int i = 1; i < n; i++) {
            if (sum >= 0) {
                sum += num[i];
            } else {
                sum = num[i];
            }
            if (sum > max) max = sum;
        }
        System.out.println(max);

    }
}